import express from 'express';
import { getAccount } from '../../../middleWare/user/index.js';
import { countSql, getResult, listSql } from '../../../util/operateSql.js';

var router = express.Router();
/* GET users listing. */

const TABLE1 = 'activity_master.t_orgnization'

router.get('/person/list', getAccount, async (req, res, next) => {
  const {id:merchant_id} = req.master
  try {
    const sql = listSql(TABLE1,{...req.query,merchant_id,is_manage:0})
    const sql2 = countSql(TABLE1,{...req.query,merchant_id,is_manage:0})
    const rows = await getResult(sql)
    const countRows = await getResult(sql2)
    res.json(req.app.locals.success({list: rows,total: countRows[0].count}))
  } catch (error) {
    res.json(req.app.locals.error(error))
  }

})

export default router